<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <!--公用头部-->
    <th:block th:replace="common/head::commonHead('新建和重命名文件夹-小邑')"/>
    <style>
        #formAdvForm .layui-row {
            margin-top: 20px;
        }
        #formAdvForm .layui-form-item {
            margin-bottom: 0;
        }
        #formAdvForm .layui-form-item .layui-inline {
            margin-bottom: 25px;
            margin-right: 0;
        }
    </style>
</head>
<!--公用js-->
<th:block th:replace="common/head::commonJs"/>
<script>
    var parentId = null ;
    var id = null ;
    var type = null ;
    var url  = null;
    $(function (){
        parentId = utils.request.getQueryString("parentId");
        id = utils.request.getQueryString("id");
        type = utils.request.getQueryString("type");
        $("#parentId").val(parentId);
    })
</script>
<body>
<form class="layui-form" action="" id="formAdvForm" lay-filter="formAdvForm">
    <div class="layui-fluid layui-fluid-btn">
        <div class="layui-card">
            <div class="layui-card-body">
                <input name="id" type="text" id="keyWord_id" style="display: none">
                <input name="parentId" type="text" id="parentId" style="display: none">
                <div class="layui-form-item layui-row">
                    <div class="layui-inline layui-col-md12">
                        <label class="layui-form-label layui-form-required">名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="fileName" id="fileName" lay-verify="required" onkeyup="this.value=this.value.replace(/[, ]/g,'').replace(/\./g,'')" placeholder="请输入文件夹名称"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="form-group-bottom">
                    <button class="xy-btn xy-btn-primary subCheckBtn" lay-submit lay-filter="formBtn">提交</button>
                    <button type="reset" class="xy-btn">重置</button>
                </div>
            </div>
        </div>
    </div>
</form>
<script>
    layui.use(['layer', 'jquery', 'form', 'notice'], function () {
        var $ = layui.jquery
            , form = layui.form
            , notice = layui.notice
            , layer = layui.layer;


        //监听提交
        form.on('submit(formBtn)', function (data) {
            var formDate = data.field;
            formDate.filePath = parent.filePath;
            if (type == 2){
                if (!utils.string.isEmpty(formDate.id)){
                    formDate.id = id;
                }
            }
            if (!utils.string.isEmpty(formDate.parentId)){
                formDate.parentId = parentId;
            }
            var loadIndex = null;
            checkSubBtn(1);
            sendAjaxPostToCallback(
                url,
                formDate,
                function (data){
                    if (data.success){
                        // 提示信息
                        top.layui.notice.msg(data.msg ,{icon: 1,position:"topCenter"});
                        // 获取当前iframe层的索引
                        var index = parent.layer.getFrameIndex(window.name);
                        // 关闭弹窗
                        parent.layer.close(index);
                    }else {
                        checkSubBtn(2);
                        top.layui.notice.msg(data.msg ,{icon: 2,position:"topCenter"});
                    }
                },
                function (data) {
                    checkSubBtn(2);
                    if (utils.string.isEmpty(data) && utils.string.isEmpty(data.msg)){
                        top.layui.notice.msg(data.msg ,{icon: 2,position:"topCenter"});
                    }else{
                        top.layui.notice.msg("服务器内部错误，请联系管理员~", {icon: 2,position:"topCenter"});
                    }
                },
                function (){
                    loadIndex = layer.load(1);
                },
                function (){
                    layer.close(loadIndex);
                },
            )
            return false;
        });
        if (type == 2){
            //获取详情信息，填充表单
            sendAjaxPostToError(
                basePath + '/file/detailFile',
                {id: id},
                function (result){
                    if (result.success == true){
                        layui.form.val('formAdvForm', result.data);
                    }else {
                        top.layui.notice.msg(result.msg ,{icon: 2,position:"topCenter"});
                    }
                },
                function (data) {
                    if (utils.string.isEmpty(data) && utils.string.isEmpty(data.msg)){
                        top.layui.notice.msg(data.msg ,{icon: 2,position:"topCenter"});
                    }else{
                        top.layui.notice.msg("服务器内部错误，请联系管理员~", {icon: 2,position:"topCenter"});
                    }
                }
            )
            url = basePath + '/file/editFolder';
        }else {
            url = basePath + '/file/addFolder';
        }
    });
</script>
</body>
</html>
